<template>
  <div :id="id" :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from "echarts";
import resize from "./mixins/resize.js";

export default {
  mixins: [resize],
  watch: {
    options: {
      handler(options) {
        this.chart.setOption(options);
      },
      deep: true
    }
  },
  props: {
    className: {
      type: String,
      default: "chart"
    },
    id: {
      type: String,
      default: "chart"
    },
    width: {
      type: String,
      default: "200px"
    },
    height: {
      type: String,
      default: "300px"
    },
    options: {
      type: Object
    }
  },
  data() {
    return {
      chart: null
    };
  },
  mounted() {
    this.initChart(this.options);
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart(options) {
      echarts.registerTheme("macarons", {
        color: [
          "#2ec7c9",
          "#b6a2de",
          "#5ab1ef",
          "#ffb980",
          "#d87a80",
          "#8d98b3",
          "#e5cf0d",
          "#97b552",
          "#95706d",
          "#dc69aa",
          "#07a2a4",
          "#9a7fd1",
          "#588dd5",
          "#f5994e",
          "#c05050",
          "#59678c",
          "#c9ab00",
          "#7eb00a",
          "#6f5553",
          "#c14089"
        ],
        // backgroundColor: "rgba(0,0,0,0)",
        textStyle: {},
        title: {
          textStyle: {
            color: "#999"
          },
          subtextStyle: {
            color: "#999"
          }
        },



      });
      this.chart = echarts.init(document.getElementById(this.id), "macarons");
      this.chart.setOption(options);
    }
  }
};
</script>


